package com.wu.orderserver.controller;

import com.wu.orderserver.entity.OrderData;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author benjamin_5
 * @Description 订单接口
 * @date 2022/7/31
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Value("${wu.order.address}")
    private String address;

    @Value("${order.title}")
    private String title;

    @Autowired
    private Environment environment;

    @Autowired
    private OrderData orderData;

    @GetMapping("list")
    public List<OrderData> list(){
        List<OrderData> list = new ArrayList<>();
        OrderData order = new OrderData();
        order.setId(1L);
        order.setOrderNo("DH111");
        order.setAddress("上海路101号");
        order.setPrice(new BigDecimal("100.0"));
        list.add(order);
        return list;
    }

    @GetMapping("get")
    public OrderData get(){
        return orderData;
    }

    @GetMapping("address")
    public String address(){
        return address;
    }

    @GetMapping("address2")
    public String address2(){
        return environment.getProperty("wu.order.address");
    }

    @GetMapping("title")
    public String title(){
        return title;
    }

}
